/*
 * Name: $RCSfile: CustomDialog.java,v $
 * Version: $Revision: 1.1 $
 * Date: $Date: Dec 28, 2011 6:53:40 PM $
 *
 * Copyright (C) 2011 COMPANY_NAME, Inc. All rights reserved.
 */

package son.hut.vn.app.utility;

import son.hut.vn.app.R;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * @author sonnv6207
 * 
 * Xay dung tat ca cac dialog su dung trong ung dung
 * 
 */
public class SmartDialogUtility extends Dialog
{

    private TextView titleTxt;

    private ImageView iconImg;

    private TextView messageTxt;

    private ImageView positiveBtn;

    private ImageView negativeBtn;

    private DialogInterface.OnDismissListener positiveDismissListener;

    private DialogInterface.OnDismissListener negativeDismissListener;

    private View.OnClickListener positiveBtnClick = new View.OnClickListener() {

        @Override
        public void onClick(View v)
        {
            setOnDismissListener(positiveDismissListener);
            dismiss();
        }
    };

    private View.OnClickListener negativeBtnClick = new View.OnClickListener() {

        @Override
        public void onClick(View v)
        {
            setOnDismissListener(negativeDismissListener);
            dismiss();
        }
    };
    
    private View.OnClickListener defaulDismiss = new View.OnClickListener() {
        
        @Override
        public void onClick(View v)
        {
            dismiss();
        }
    };



    public SmartDialogUtility(Context context, int titleId, int iconId,
        int messageId, int positiveBtnId)
    {
        super(context);
        /** 'Window.FEATURE_NO_TITLE' - Used to hide the title */
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.custom_dialog_positive_page);

        titleTxt = (TextView) findViewById(R.id.titleTxt);
        titleTxt.setText(context.getString(titleId));

        iconImg = (ImageView) findViewById(R.id.iconImg);
        iconImg.setImageResource(iconId);

        messageTxt = (TextView) findViewById(R.id.messageTxt);
        messageTxt.setText(context.getString(messageId));

        positiveBtn = (ImageView) findViewById(R.id.positiveBtn);
        positiveBtn.setImageResource(positiveBtnId);
        positiveBtn.setOnClickListener(defaulDismiss);
    }
    
    /**
     * Constructor
     * @param context
     * @param titleId
     * @param iconId
     * @param message
     * @param positiveBtnId
     */
    public SmartDialogUtility(Context context, int titleId, int iconId,
        String message, int positiveBtnId)
    {
        super(context);
        /** 'Window.FEATURE_NO_TITLE' - Used to hide the title */
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.custom_dialog_positive_page);

        titleTxt = (TextView) findViewById(R.id.titleTxt);
        titleTxt.setText(context.getString(titleId));

        iconImg = (ImageView) findViewById(R.id.iconImg);
        iconImg.setImageResource(iconId);

        messageTxt = (TextView) findViewById(R.id.messageTxt);
        messageTxt.setText(message);

        positiveBtn = (ImageView) findViewById(R.id.positiveBtn);
        positiveBtn.setImageResource(positiveBtnId);
        positiveBtn.setOnClickListener(defaulDismiss);
    }
}
